package des.wangku.operate;

import java.io.InputStream;

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;

import des.wangku.operate.standard.desktop.DesktopConst;
import des.wangku.operate.standard.desktop.DesktopUtils;
import des.wangku.operate.standard.dialog.DialogShow;
import des.wangku.operate.standard.dialog.HelpDialog;
import des.wangku.operate.standard.dialog.RunDialog;
import des.wangku.operate.standard.utls.UtilsSWTMessageBox;

public class Desktop_Menu {
	/**
	 * 初始化菜单
	 */
	static final void initializationMenu() {
		Desktop.compositeMain.setBounds(0, 0, 900, 550);
		Desktop_Menu.initializationTaskMenu();
		Desktop_Menu.initializationSetMenu();
		Desktop_Menu.initializationToolsMenu();
		Desktop_Menu.initializationVersionMenu();
		Desktop_Menu.initializationExitMenu();
		
	}
	/**
	 * 修改版本菜单
	 */
	static final void initializationExitMenu() {
		MenuItem menuItem_exit = new MenuItem(Desktop.menu, SWT.NONE);
		menuItem_exit.setText("退出");
		menuItem_exit.setAccelerator(SWT.CTRL + 'Q');
		menuItem_exit.setImage(ImageConst.ACC_M0exit);
		menuItem_exit.addListener(SWT.Selection, new Listener() {
			public void handleEvent(Event e) {
				DesktopUtils.existProject(Desktop.compositeMain);
				Desktop.shell.dispose();
				//System.exit(0);
			}
		});
	}
	/**
	 * 修改版本菜单
	 */
	static final void initializationVersionMenu() {
		MenuItem menuVersionList = new MenuItem(Desktop.menu, SWT.CASCADE);
		menuVersionList.setText("版本信息");
		menuVersionList.setImage(ImageConst.ACC_M0ver);
		Menu menuVersion = new Menu(menuVersionList);
		menuVersionList.setMenu(menuVersion);
		MenuItem menuItem_21 = new MenuItem(menuVersion, SWT.NONE);
		menuItem_21.setText("版本\tCtrl+S");
		menuItem_21.setAccelerator(SWT.CTRL + 'S');
		menuItem_21.setImage(ImageConst.getImagesIcon("version.gif"));
		menuItem_21.addListener(SWT.Selection, new Listener() {
			public void handleEvent(Event e) {
				InputStream is = Const.class.getClassLoader().getResourceAsStream("update.info");
				HelpDialog ver = new HelpDialog(Desktop.shell, 0, is);
				ver.open();
			}
		});
	}
	/**
	 * 修改工具菜单
	 */
	static final void initializationToolsMenu() {
		MenuItem menuVersionList = new MenuItem(Desktop.menu, SWT.CASCADE);
		menuVersionList.setText("简易工具");
		menuVersionList.setImage(ImageConst.getImagesIcon("more.gif"));
		Menu menuVersion = new Menu(menuVersionList);
		menuVersionList.setMenu(menuVersion);
		MenuItem menuItem_21 = new MenuItem(menuVersion, SWT.NONE);
		menuItem_21.setText("文本修改器\tCtrl+E");
		menuItem_21.setAccelerator(SWT.CTRL + 'E');
		menuItem_21.setImage(ImageConst.getImagesIcon("tools.gif"));
		menuItem_21.addListener(SWT.Selection, new Listener() {
			public void handleEvent(Event e) {
				DialogShow.showTextContent();
			}
		});
	}
	/**
	 * 修改任务菜单
	 */
	static final void initializationTaskMenu() {
		Desktop.menuItemCommondList.setText("任务列表");
		Desktop.menuItemCommondList.setEnabled(false);
		Desktop.menuItemCommondList.setImage(ImageConst.ACC_M0task);
		Desktop.menu_List = new Menu(Desktop.menuItemCommondList);
		Desktop.menuItemCommondList.setMenu(Desktop.menu_List);
	}

	/**
	 * 修改设置菜单
	 */
	static final void initializationSetMenu() {
		MenuItem set = new MenuItem(Desktop.menu, SWT.CASCADE);
		set.setText("设置");
		set.setEnabled(true);
		set.setImage(ImageConst.ACC_M0set);
		Menu menu_Set = new Menu(set);
		set.setMenu(menu_Set);
		MenuItem menuItem = new MenuItem(menu_Set, SWT.CASCADE);
		menuItem.setText("声音");
		menuItem.setImage(ImageConst.getImagesIcon("voice.ico"));
		Menu menuGroup = new Menu(Desktop.shell, SWT.DROP_DOWN);
		menuItem.setMenu(menuGroup);
		{
			MenuItem m = new MenuItem(menuGroup, SWT.CHECK);
			boolean val = DesktopConst.isSysMSVwarning;
			m.setSelection(val);
			UtilsSWTMessageBox.VOICE_AlERT = val;
			m.setText("提示警告");
			m.addListener(SWT.Selection, new Listener() {
				public void handleEvent(Event e) {
					UtilsSWTMessageBox.VOICE_AlERT = m.getSelection();
				}
			});
		}
		{
			MenuItem m = new MenuItem(menuGroup, SWT.CHECK);
			boolean val = DesktopConst.isSysMSVconfirm;
			m.setSelection(val);
			UtilsSWTMessageBox.VOICE_CONFIRM = val;
			m.setText("确认弹窗");
			m.addListener(SWT.Selection, new Listener() {
				public void handleEvent(Event e) {
					UtilsSWTMessageBox.VOICE_CONFIRM = m.getSelection();
				}
			});

		}
		{
			MenuItem m = new MenuItem(menuGroup, SWT.CHECK);
			boolean val = DesktopConst.isSysMSVthread;
			m.setSelection(val);
			RunDialog.VOICE_RUNDIALOG = val;
			m.setText("线程结束");
			m.addListener(SWT.Selection, new Listener() {
				public void handleEvent(Event e) {
					RunDialog.VOICE_RUNDIALOG = m.getSelection();
				}
			});
		}
		MenuItem menuItemRem = new MenuItem(menu_Set, SWT.CASCADE);
		menuItemRem.setText("记录");
		menuItemRem.setImage(ImageConst.getImagesIcon("Memory.ico"));
		Menu menuGroupRem = new Menu(Desktop.shell, SWT.DROP_DOWN);
		menuItemRem.setMenu(menuGroupRem);
		{
			MenuItem m = new MenuItem(menuGroupRem, SWT.CHECK);
			m.setSelection(DesktopConst.isRemember_Input);
			m.setText("输入框记忆");
			m.addListener(SWT.Selection, new Listener() {
				public void handleEvent(Event e) {
					DesktopConst.isRemember_Input = m.getSelection();
				}
			});
		}
	}

}
